package com.sam.im.heiqun.uis.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.afollestad.materialcamera.internal.PlayNewActivity;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.CircleNums;
import com.sam.im.heiqun.entities.CommontsEntity;
import com.sam.im.heiqun.entities.FeedPraisesEntity;
import com.sam.im.heiqun.entities.MyCircleItem;
import com.sam.im.heiqun.entities.VedioEntity;
import com.sam.im.heiqun.entities.beans.CollectInfo;
import com.sam.im.heiqun.entities.beans.ImageInfoBean;
import com.sam.im.heiqun.mvp.modle.ActionItem;
import com.sam.im.heiqun.mvp.modle.CommentConfig;
import com.sam.im.heiqun.mvp.modle.PhotoInfo;
import com.sam.im.heiqun.mvp.modle.User;
import com.sam.im.heiqun.mvp.presenter.CirclePresenter;
import com.sam.im.heiqun.uis.activities.CircleActivity;
import com.sam.im.heiqun.uis.activities.FriendDetailActivity;
import com.sam.im.heiqun.uis.activities.ImagePagerActivity;
import com.sam.im.heiqun.uis.activities.MycircleActivty;
import com.sam.im.heiqun.uis.activities.Play2Activity;
import com.sam.im.heiqun.uis.activities.PlayActivity;
import com.sam.im.heiqun.uis.adapters.holder.CircleViewHolder;
import com.sam.im.heiqun.uis.adapters.holder.ImageViewHolder;
import com.sam.im.heiqun.uis.adapters.holder.URLViewHolder;
import com.sam.im.heiqun.utils.JsonUtil;
import com.sam.im.heiqun.utils.ToolsUtils;
import com.sam.im.heiqun.utils.circleutils.UrlUtils;
import com.sam.im.heiqun.widgets.CommentListView;
import com.sam.im.heiqun.widgets.ExpandTextView;
import com.sam.im.heiqun.widgets.MultiImageView;
import com.sam.im.heiqun.widgets.PraiseListView;
import com.sam.im.heiqun.widgets.SnsPopupWindow;
import com.yuyh.library.utils.TimeUtil;
import com.yuyh.library.view.image.CircleImageView;

import java.util.ArrayList;
import java.util.List;

import com.sam.im.heiqun.utils.StringUtils;

/**
 * Created by yiwei on 16/5/17.
 */
public class CircleAdapter extends BaseRecycleViewAdapter {

    public final static int TYPE_HEAD = 0;
    public final static int TYPE_BODY = 1;

    private static final int STATE_IDLE = 0;
    private static final int STATE_ACTIVED = 1;
    private static final int STATE_DEACTIVED = 2;
    private int videoState = STATE_IDLE;
    public static final int HEADVIEW_SIZE = 1;
    int curPlayIndex = -1;
    private CirclePresenter presenter;
    private Context context;
    private int unread;
    private CircleNums circleNums ;
    private OnnewsItemOclickListenler onnewsItemOclickListenler ;
    private OnbackgroudClickListenler onbackgroudClickListenler ;
    private String backgroudUrl  ;

    public void setBackgroudUrl(String backgroudUrl) {
        this.backgroudUrl = backgroudUrl;
//        notifyDataSetChanged();
        try {
            CircleAdapter.this.notifyItemChanged(0);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void setOnbackgroudClickListenler(OnbackgroudClickListenler onbackgroudClickListenler) {
        this.onbackgroudClickListenler = onbackgroudClickListenler;
    }

    public void setOnnewsItemOclickListenler(OnnewsItemOclickListenler onnewsItemOclickListenler) {
        this.onnewsItemOclickListenler = onnewsItemOclickListenler;
    }

    public void setUnread(int unread,CircleNums circleNums) {
        this.unread = unread;
        this.circleNums = circleNums ;
//        notifyDataSetChanged();
        try {
            CircleAdapter.this.notifyItemChanged(0);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public void setCirclePresenter(CirclePresenter presenter) {
        this.presenter = presenter;
    }

    public CircleAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_HEAD;
        } else {
            return TYPE_BODY;
        }
       /* int itemType = 0;
        MyCircleItem.ListBean item = (MyCircleItem.ListBean) datas.get(position-1);
        if (CircleItem.TYPE_URL.equals(item.getType())) {
            itemType = CircleViewHolder.TYPE_URL;
        } else if (CircleItem.TYPE_IMG.equals(item.getType())) {
            itemType = CircleViewHolder.TYPE_IMAGE;
        } else if(CircleItem.TYPE_VIDEO.equals(item.getType())){
            itemType = CircleViewHolder.TYPE_VIDEO;
        }*/
        //return TYPE_BODY;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder = null;
        if (viewType == TYPE_HEAD) {
            View headView = LayoutInflater.from(parent.getContext()).inflate(R.layout.head_circle, parent, false);
            viewHolder = new HeaderViewHolder(headView);
        } else {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_circle_item, parent, false);
            viewHolder = new ImageViewHolder(view);
            /*if(viewType == CircleViewHolder.TYPE_URL){
                viewHolder = new URLViewHolder(view);
            }else if(viewType == CircleViewHolder.TYPE_IMAGE){
                viewHolder = new ImageViewHolder(view);
            }else if(viewType == CircleViewHolder.TYPE_VIDEO){
                viewHolder = new VideoViewHolder(view);
            }*/
        }
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        Log.i("info", "type==" + getItemViewType(position));
        if (getItemViewType(position) == TYPE_HEAD) {
            setheadlayout((HeaderViewHolder) viewHolder);
            //HeaderViewHolder holder = (HeaderViewHolder) viewHolder;
        } else {
            final int circlePosition = position - HEADVIEW_SIZE;
            final CircleViewHolder holder = (CircleViewHolder) viewHolder;
            final MyCircleItem.ListBean listBean = (MyCircleItem.ListBean) datas.get(circlePosition);
            //final CircleItem circleItem = (CircleItem) datas.get(circlePosition);

            final String circleId = listBean.getBelongUserId();//发的人id
            String userHeadUrl = listBean.getUserHeadUrl();//头像

            String userName = ToolsUtils.getFriendRemarkName(listBean.getUserId());//昵称
            if ("".equals(userName)){
                userName = listBean.getUserName();//昵称
            }
//            String userName = listBean.getUserName();//昵称
            // String name =             //昵称
            //  String headImg = circleItem.getUser().getHeadUrl();
            final String content = listBean.getFeedText();
            final String feedimg = listBean.getFeedImgs();
            String createTime = listBean.getCreateTime(); //发布时间
            List<CommontsEntity> imFeedCommentsa = new ArrayList<>();;
            if (null!=listBean.getImFeedComments()){
                imFeedCommentsa = listBean.getImFeedComments();//评论
            }
            final List<CommontsEntity> imFeedComments = imFeedCommentsa;
            List<FeedPraisesEntity> imFeedPraises = listBean.getImFeedPraises();//点赞

            if (null==imFeedPraises)imFeedPraises = new ArrayList<>();
            String id = listBean.getLId();//id
            final String feedId = listBean.getFeedId();
            String userId = listBean.getUserId();
            String status = listBean.getStatus();
            // Glide.with(context).load(userHeadUrl).into(holder.headIv);
            Glide.with(context).load(userHeadUrl).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.color.bg_no_photo).centerCrop().into(holder.headIv);
            holder.headIv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, FriendDetailActivity.class);
                    intent.putExtra("type", 0);
                    intent.putExtra("id", Long.parseLong(listBean.getUserId()));
                    context.startActivity(intent);
                }
            });
            holder.nameTv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, FriendDetailActivity.class);
                    intent.putExtra("type", 0);
                    intent.putExtra("id", Long.parseLong(listBean.getUserId()));
                    context.startActivity(intent);
                }
            });
            holder.nameTv.setText(userName);
            long l = Long.parseLong(createTime);
            String recentlyTime = TimeUtil.getRecentlyTime(l);
            holder.timeTv.setText(recentlyTime);
            if (!TextUtils.isEmpty(content)) {
                holder.contentTv.setExpand(listBean.isExpand());
                holder.contentTv.setExpandStatusListener(new ExpandTextView.ExpandStatusListener() {
                    @Override
                    public void statusChange(boolean isExpand) {
                        listBean.setExpand(isExpand);
                    }
                });
                holder.contentTv.setText(UrlUtils.formatUrlString(content));
            }
            holder.contentTv.setVisibility(TextUtils.isEmpty(content) ? View.GONE : View.VISIBLE);
            if (position==1){
                holder.dividerview.setVisibility(View.GONE);
            }else {
                holder.dividerview.setVisibility(View.VISIBLE);
            }

            if (null!=listBean.getAddress() && !"".equals(listBean.getAddress())){
                holder.txt_address.setText(listBean.getAddress());
                holder.txt_address.setVisibility(View.VISIBLE);
            }else {
                holder.txt_address.setVisibility(View.GONE);
            }

            //这里判断是否是自己的消息  暂时没有删除功能
            if(ToolsUtils.getMyUserId().equals(userId)){
                holder.deleteBtn.setVisibility(View.VISIBLE);
            }else{
                holder.deleteBtn.setVisibility(View.GONE);
            }
            //删除
            holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //删除
                    if(presenter!=null){
                        presenter.deleteCircle(feedId);
                    }
                }
            });

            //有点赞或者有评论
            if (null!=imFeedComments && null!=imFeedPraises && (imFeedComments.size() > 0 || imFeedPraises.size() > 0)) {
                if (imFeedPraises.size() > 0) {//处理点赞列表
                    holder.praiseListView.setOnItemClickListener(new PraiseListView.OnItemClickListener() {
                        @Override
                        public void onClick(int position) {
                            // String userName = favortDatas.get(position).getUser().getName();
                            // String userId = favortDatas.get(position).getUser().getId();
                            // Toast.makeText(App.getInstance().getApplicationContext(), userName + " &id = " + userId, Toast.LENGTH_SHORT).show();
                        }
                    });
                    holder.praiseListView.setDatas(imFeedPraises);
                    holder.praiseListView.setVisibility(View.VISIBLE);
                } else {
                    holder.praiseListView.setVisibility(View.GONE);
                }
                if (imFeedComments.size() > 0) {//处理评论列表
                    holder.commentList.setOnItemClickListener(new CommentListView.OnItemClickListener() {
                        @Override
                        public void onItemClick(int commentPosition) {
                            // CommentItem commentItem = commentsDatas.get(commentPosition);
                            if (imFeedComments.get(commentPosition).getUserId().equals(ToolsUtils.getMyUserId())) {//这里的回复是自己的
                                Toast.makeText(context, context.getResources().getString(R.string.circle_this_is_your), Toast.LENGTH_SHORT).show();
                                // CommentDialog dialog = new CommentDialog(context, presenter, listBean, circlePosition);
                                //   dialog.show();
                            } else {//回复别人的评论
                                if (presenter != null) {
                                    CommentConfig config = new CommentConfig();
                                    config.circlePosition = circlePosition;
                                    config.commentPosition = commentPosition;
                                    config.commentType = CommentConfig.Type.REPLY;
                                    config.setReplyUserid(imFeedComments.get(commentPosition).getUserId());
                                    User reply = new User(imFeedComments.get(commentPosition).getUserId(),
                                            imFeedComments.get(commentPosition).getUserName(),imFeedComments.get(commentPosition).getUserHeadUrl());
                                    config.replyUser = reply;
                                    presenter.showEditTextBody(config);
                                }
                            }
                        }
                    });
                    holder.commentList.setOnItemLongClickListener(new CommentListView.OnItemLongClickListener() {
                        @Override
                        public void onItemLongClick(int commentPosition) {
                            //长按进行复制或者删除
                            //  CommentItem commentItem = commentsDatas.get(commentPosition);
                            //  CommentDialog dialog = new CommentDialog(context, presenter, commentItem, circlePosition);
                            // dialog.show();
                        }
                    });
                    holder.commentList.setDatas(imFeedComments);
                    holder.commentList.setVisibility(View.VISIBLE);

                } else {
                    holder.commentList.setVisibility(View.GONE);
                }
                holder.digCommentBody.setVisibility(View.VISIBLE);
            } else {
                holder.digCommentBody.setVisibility(View.GONE);
            }

            //  holder.digLine.setVisibility(imFeedComments.size()>0 && imFeedPraises.size()>0 ? View.VISIBLE : View.GONE);

            final SnsPopupWindow snsPopupWindow = holder.snsPopupWindow;
            //判断是否已点赞
            boolean ispraise = false;
            if (imFeedPraises.size() > 0) {
                for (int i = 0; i < imFeedPraises.size(); i++) {
                    FeedPraisesEntity imFeedPraisesBean = imFeedPraises.get(i);
                    String userId1 = imFeedPraisesBean.getUserId();//点赞人的id  这里暂不取消赞 如果已经有赞就不能再次赞了
                    if (userId1.equals(ToolsUtils.getMyUserId())) {
                        ispraise = true;
                        break;
                    }
                }
            }
            if (ispraise) {//已经赞了
                snsPopupWindow.getmActionItems().get(0).mTitle = context.getResources().getString(R.string.cancel);
            } else {
                snsPopupWindow.getmActionItems().get(0).mTitle = context.getResources().getString(R.string.zan);
            }
            // String curUserFavortId = circleItem.getCurUserFavortId(DatasUtil.curUser.getId());
           /* if(!TextUtils.isEmpty(curUserFavortId)){
                snsPopupWindow.getmActionItems().get(0).mTitle = "取消";
            }else{
                snsPopupWindow.getmActionItems().get(0).mTitle = "赞";
            }*/
            snsPopupWindow.update();
            snsPopupWindow.setmItemClickListener(new PopupItemClickListener(circlePosition, listBean, ToolsUtils.getMyUserId()));
            holder.snsBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //弹出popupwindow
                    snsPopupWindow.showPopupWindow(view);
                }
            });
            holder.urlTipTv.setVisibility(View.GONE);

            int thisCircleType = 0 ;//0-文字图片；1-视频；2-URL

            if (listBean.getFeedVideo().length() > 0 && feedimg.length() > 0){
                thisCircleType = 1 ;
            }else {
                thisCircleType = 0 ;
            }
            try {
                ((ImageViewHolder) holder).image_startvideo.setVisibility(View.GONE);
            }catch (Exception e){
                e.printStackTrace();
            }

            switch (thisCircleType){
                case 0 ://文字图片
                    if (holder instanceof ImageViewHolder) {
                        final List<PhotoInfo> photos = new ArrayList<>();
                        if (!StringUtils.isEmpty(feedimg)) {
                            if (feedimg.contains(",")){
                                String[] splitimg = feedimg.split(",");
                                for (int e = 0; e < splitimg.length;e++){
                                    PhotoInfo photoInfo = new PhotoInfo();
                                    photoInfo.url = splitimg[e];
                                    photos.add(photoInfo);
                                }
                            }else {
                                PhotoInfo photoInfo = new PhotoInfo();
                                photoInfo.url = feedimg;
                                photos.add(photoInfo);
                            }
                            if (photos != null && photos.size() > 0) {
                                ((ImageViewHolder) holder).multiImageView.setVisibility(View.VISIBLE);
                                ((ImageViewHolder) holder).multiImageView.setList(photos);
                                ((ImageViewHolder) holder).multiImageView.setOnItemClickListener(new MultiImageView.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(View view, int position) {
                                        //imagesize是作为loading时的图片size
                                        ImagePagerActivity.ImageSize imageSize = new ImagePagerActivity.ImageSize(view.getMeasuredWidth(), view.getMeasuredHeight());
                                        List<ImageInfoBean> photoUrls = new ArrayList<>();
                                        for (PhotoInfo photoInfo : photos) {
                                            photoUrls.add(new ImageInfoBean(photoInfo.url,true));
                                        }
                                        ImagePagerActivity.startImagePagerActivity(((CircleActivity) context), photoUrls, position, imageSize);
                                    }
                                });
                            } else {
                                photos.clear();
                                ((ImageViewHolder) holder).multiImageView.setVisibility(View.VISIBLE);
                                ((ImageViewHolder) holder).multiImageView.setList(photos);
                            }
                        }else {

                            ((ImageViewHolder) holder).multiImageView.setVisibility(View.GONE);
                        }
                    }
                    break;
                case 1 ://视频
                    final List<PhotoInfo> photos = new ArrayList<>();
                    if (!StringUtils.isEmpty(feedimg)) {

                        PhotoInfo photoInfo = new PhotoInfo();
                        photoInfo.url = feedimg;
                        photos.add(photoInfo);

                        if (photos != null && photos.size() > 0) {
                            ((ImageViewHolder) holder).multiImageView.setVisibility(View.VISIBLE);
                            ((ImageViewHolder) holder).multiImageView.setList(photos);
                            ((ImageViewHolder) holder).multiImageView.setOnItemClickListener(new MultiImageView.OnItemClickListener() {
                                @Override
                                public void onItemClick(View view, int position) {

                                    Log.i("=====", "onItemClick: =========去看看这个小视频=======");

                                    VedioEntity vedioEntity = new VedioEntity();
                                    vedioEntity.setCanForward(true);
                                    vedioEntity.setVedioUrl(listBean.getFeedVideo());
                                    vedioEntity.setGetVedioBitmapUrl(listBean.getFeedImgs());
                                    CollectInfo collectInfo = new CollectInfo();
                                    collectInfo.setCategory("4");
                                    collectInfo.setFromid(listBean.getUserId());
                                    collectInfo.setFromname(listBean.getUserName());
                                    collectInfo.setUrl(listBean.getFeedVideo());
                                    collectInfo.setContent(JsonUtil.toJson(vedioEntity));
                                    Intent intent = Play2Activity.newIntent(context, listBean.getFeedVideo(), vedioEntity, collectInfo);
                                    context.startActivity(intent);
                                    //imagesize是作为loading时的图片size
//                                    ImagePagerActivity.ImageSize imageSize = new ImagePagerActivity.ImageSize(view.getMeasuredWidth(), view.getMeasuredHeight());
//                                    List<String> photoUrls = new ArrayList<String>();
//                                    for (PhotoInfo photoInfo : photos) {
//                                        photoUrls.add(photoInfo.url);
//                                    }
//                                    ImagePagerActivity.startImagePagerActivity(((CircleActivity) context), photoUrls, position, imageSize);
                                }
                            });
                        } else {
                            photos.clear();
                            ((ImageViewHolder) holder).multiImageView.setVisibility(View.VISIBLE);
                            ((ImageViewHolder) holder).multiImageView.setList(photos);
                        }
                        ((ImageViewHolder) holder).image_startvideo.setVisibility(View.VISIBLE);
                    }else {
                        ((ImageViewHolder) holder).multiImageView.setVisibility(View.GONE);
                        ((ImageViewHolder) holder).image_startvideo.setVisibility(View.GONE);
                    }
                    break;
                case 2 ://URL
                    break;
            }


            switch (holder.viewType) {
                case CircleViewHolder.TYPE_URL:// 处理链接动态的链接内容和和图片
                    if (holder instanceof URLViewHolder) {
                        String linkImg = listBean.getFeedImgs();
                        String linkTitle = listBean.getFeedText();
                        Glide.with(context).load(linkImg).into(((URLViewHolder) holder).urlImageIv);
                        ((URLViewHolder) holder).urlContentTv.setText(linkTitle);
                        ((URLViewHolder) holder).urlBody.setVisibility(View.VISIBLE);
                        ((URLViewHolder) holder).urlTipTv.setVisibility(View.VISIBLE);
                    }
                    break;
                case CircleViewHolder.TYPE_IMAGE:// 处理图片
                   /* if(holder instanceof ImageViewHolder){
                        final List<PhotoInfo> photos = circleItem.getPhotos();
                        if (photos != null && photos.size() > 0) {
                            ((ImageViewHolder)holder).multiImageView.setVisibility(View.VISIBLE);
                            ((ImageViewHolder)holder).multiImageView.setList(photos);
                            ((ImageViewHolder)holder).multiImageView.setOnItemClickListener(new MultiImageView.OnItemClickListener() {
                                @Override
                                public void onItemClick(View view, int position) {
                                    //imagesize是作为loading时的图片size
                                    ImagePagerActivity.ImageSize imageSize = new ImagePagerActivity.ImageSize(view.getMeasuredWidth(), view.getMeasuredHeight());

                                    List<String> photoUrls = new ArrayList<String>();
                                    for(PhotoInfo photoInfo : photos){
                                        photoUrls.add(photoInfo.url);
                                    }
                                    ImagePagerActivity.startImagePagerActivity(((CircleActivity) context), photoUrls, position, imageSize);


                                }
                            });
                        } else {
                            ((ImageViewHolder)holder).multiImageView.setVisibility(View.GONE);
                        }
                    }
*/
                    break;
                case CircleViewHolder.TYPE_VIDEO:
//                    if(holder instanceof VideoViewHolder){
//                        ((VideoViewHolder)holder).videoView.setVideoUrl(circleItem.getVideoUrl());
//                        ((VideoViewHolder)holder).videoView.setVideoImgUrl(circleItem.getVideoImgUrl());//视频封面图片
//                        ((VideoViewHolder)holder).videoView.setPostion(position);
//                        ((VideoViewHolder)holder).videoView.setOnPlayClickListener(new CircleVideoView.OnPlayClickListener() {
//                            @Override
//                            public void onPlayClick(int pos) {
//                                curPlayIndex = pos;
//                            }
//                        });
//                    }

                    break;
                default:
                    break;
            }
        }
    }

    private void setheadlayout(final HeaderViewHolder viewHolder) {
        viewHolder.imicon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.startActivity(new Intent(context, MycircleActivty.class));

            }
        });


        if (backgroudUrl!=null&&!StringUtils.isEmpty(backgroudUrl)){
            Glide.with(context).load(backgroudUrl).into(viewHolder.imbg);
        }
        viewHolder.imbg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onbackgroudClickListenler != null) {
                    onbackgroudClickListenler.backgroudclick(viewHolder.imbg);
                }
            }
        });
        Glide.with(context).load(ToolsUtils.getUser().getHeadUrl()).error(R.drawable.head_defaul).into(viewHolder.imicon);
        // GlideUtils.loadCircleCacheImage(context, ToolsUtils.getUser().getHeadUrl(),viewHolder.imicon);
        viewHolder.tvname.setText(ToolsUtils.getUser().getName());
        viewHolder.dynamicLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewHolder.dynamicLayout.setVisibility(View.GONE);
                viewHolder.dynamicLayout.setEnabled(false);
                onnewsItemOclickListenler.newsClick();
            }
        });
        if (unread!=0&&circleNums != null){
            String fromuserimgurl = circleNums.getFromuserimgurl();
            Glide.with(context).load(fromuserimgurl).centerCrop().dontAnimate().error(R.drawable.head_defaul).into(viewHolder.friendIcon);
            viewHolder.tvItem.setText(unread+context.getResources().getString(R.string.new_message_num));
            viewHolder.dynamicLayout.setVisibility(View.VISIBLE);
            viewHolder.dynamicLayout.setEnabled(true);
        }else {
            viewHolder.dynamicLayout.setVisibility(View.GONE);
            viewHolder.dynamicLayout.setEnabled(false);
        }
    }

    @Override
    public int getItemCount() {
        return datas.size() + 1;//有head需要加1
    }

    @Override
    public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
        super.onViewAttachedToWindow(holder);
    }

    public class HeaderViewHolder extends RecyclerView.ViewHolder {
        ImageView imbg;
        CircleImageView imicon;
        TextView tvname;
        LinearLayout dynamicLayout  ;
        CircleImageView friendIcon ;
        TextView tvItem ;
        public HeaderViewHolder(View itemView) {
            super(itemView);
            imbg = (ImageView) itemView.findViewById(R.id.img_bg);
            imicon = (CircleImageView) itemView.findViewById(R.id.imicon);
            tvname = (TextView) itemView.findViewById(R.id.tvname);
            dynamicLayout = (LinearLayout) itemView.findViewById(R.id.dynamic_layout);
            friendIcon = (CircleImageView) itemView.findViewById(R.id.friend_icon);
            tvItem = (TextView) itemView.findViewById(R.id.tv_item);
        }
    }

    private class PopupItemClickListener implements SnsPopupWindow.OnItemClickListener {
        private String mFavorId;
        //动态在列表中的位置
        private int mCirclePosition;
        private long mLasttime = 0;
        private MyCircleItem.ListBean mCircleItem;

        public PopupItemClickListener(int circlePosition, MyCircleItem.ListBean circleItem, String favorId) {
            this.mFavorId = favorId;
            this.mCirclePosition = circlePosition;
            this.mCircleItem = circleItem;
        }

        @Override
        public void onItemClick(ActionItem actionitem, int position) {
            switch (position) {
                case 0://点赞、取消点赞
                    if (System.currentTimeMillis() - mLasttime < 700)//防止快速点击操作
                        return;
                    mLasttime = System.currentTimeMillis();
                    if (presenter != null) {

                        if (context.getResources().getString(R.string.zan).equals(actionitem.mTitle.toString())) {
                            presenter.addFavort(mCirclePosition);
                        } else {//取消点赞
                            presenter.deleteFavort(mCirclePosition);
                            //presenter.deleteFavort(mCirclePosition, mFavorId);
                        }
                    }
                    break;
                case 1://发布评论
                    if (presenter != null) {
                        CommentConfig config = new CommentConfig();
                        config.circlePosition = mCirclePosition;
                        config.commentType = CommentConfig.Type.PUBLIC;
                        presenter.showEditTextBody(config);
                    }
                    break;
                case 2://礼物
                    if (presenter != null) {
                        CommentConfig config = new CommentConfig() ;
                        config.circlePosition = mCirclePosition ;
                        config.commentType = CommentConfig.Type.PUBLIC ;
                        presenter.showGiftSelecter(config);



                    }
                    break;
                default:
                    break;
            }
        }
    }
    public  interface OnnewsItemOclickListenler{
        void newsClick();
    }
    public interface OnbackgroudClickListenler{
        void backgroudclick(View view);
    }
}
